<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #operationAfterExtend="{ record }">
        <a-link @click="handleClick(record)">配置节点信息</a-link>
        <a-popconfirm content="是否固定/取消巡检路线？" @ok="yqgd(record)">
          <a-link >{{record.solid_ins == 2?'取消园区巡检路线':' 固定园区巡检路线'}}</a-link>
        </a-popconfirm>
        
      </template>
      <template #solid_ins="{record}">
        <div>{{ record.solid_ins == 2?'是':'否' }}</div>
      </template>
    </ma-crud>
    <a-drawer
      :width="1200"
      :visible="visible"
      @ok="handleOk"
      @cancel="handleCancel"
      unmountOnClose
    >
      <template #title>节点信息</template>
      <inspectionrouteInfo :route_ids="route_ids" v-if="visible">
      </inspectionrouteInfo>
    </a-drawer>
  </div>
</template>
<script setup>
import { ref, reactive } from "vue";
import secureInspectionrouteManage from "@/api/secure/secureInspectionrouteManage";
import inspectionrouteInfo from "@/views/secure/inspectionrouteInfo/index.vue";
import { Message } from "@arco-design/web-vue";
import tool from "@/utils/tool";
import * as common from "@/utils/common";
import { request } from "@/utils/request.js";
const crudRef = ref();
const route_ids = ref();
const visible = ref(false);

const numberOperation = (newValue, id, numberName) => {
  secureInspectionrouteManage
    .numberOperation({ id, numberName, numberValue: newValue })
    .then((res) => {
      res.success && Message.success(res.message);
    })
    .catch((e) => {
      console.log(e);
    });
};

const handleClick = (row) => {
  route_ids.value = row.id;
  visible.value = true;
};
const handleOk = () => {
  visible.value = false;
};
const handleCancel = () => {
  visible.value = false;
};
const gd_id = ref();
const yqgd = (row) => {
  let solid_ins = ''
  if(row.solid_ins == 2){
    solid_ins = 1
  }else{
    solid_ins = 2
  }
  request({
    url: "secure/inspectionrouteManage/gdaa",
    method: "get",
    params: {
        id:row.id,
        status:solid_ins,
    },
  }).then((res) => {
    Message.success("修改成功");
    crudRef.value.refresh()
  });
};

const switchStatus = (statusValue, id, statusName) => {
  secureInspectionrouteManage
    .changeStatus({ id, statusName, statusValue })
    .then((res) => {
      res.success && Message.success(res.message);
    })
    .catch((e) => {
      console.log(e);
    });
};

const options = reactive({
  id: "flyos_secure_inspectionroute_manage",
  rowSelection: {
    showCheckedAll: true,
  },
  pk: "id",
  operationColumn: true,
  operationWidth: 160,
  formOption: {
    viewType: "modal",
    width: 600,
  },
  api: secureInspectionrouteManage.getList,
  recycleApi: secureInspectionrouteManage.getRecycleList,
  add: {
    show: true,
    api: secureInspectionrouteManage.save,
    auth: ["secure:inspectionrouteManage:save"],
  },
  edit: {
    show: true,
    api: secureInspectionrouteManage.update,
    auth: ["secure:inspectionrouteManage:update"],
  },
  delete: {
    show: true,
    api: secureInspectionrouteManage.deletes,
    auth: ["secure:inspectionrouteManage:delete"],
    realApi: secureInspectionrouteManage.realDeletes,
    realAuth: ["secure:inspectionrouteManage:realDeletes"],
  },
  recovery: {
    show: true,
    api: secureInspectionrouteManage.recoverys,
    auth: ["secure:inspectionrouteManage:recovery"],
  },
  import: {
    show: true,
    url: "secure/inspectionrouteManage/import",
    templateUrl: "secure/inspectionrouteManage/downloadTemplate",
    auth: ["secure:inspectionrouteManage:import"],
  },
  export: {
    show: true,
    url: "secure/inspectionrouteManage/export",
    auth: ["secure:inspectionrouteManage:export"],
  },
});

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入ID",
    },
  },
  {
    title: "路线名称",
    dataIndex: "route_name",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入路线名称",
    },
  },
  {
    title: "时间段",
    dataIndex: "route_time",
    formType: "time",
    search: true,
    commonRules: {
      required: false,
      message: "请输入时间段",
    },
    range: true,
  },
  {
    title: "节点信息",
    dataIndex: "not_node_info",
    addDisplay: false,
    editDisplay: false,
  },
  {
    title: "重复类型",
    dataIndex: "not_status_type",
    addDisplay: false,
    editDisplay: false,
  },
  {
    title: "是否固定为园区巡检",
    dataIndex: "solid_ins",
    addDisplay: false,
    editDisplay: false,
  },
  
  {
    title: "是否重复设置",
    dataIndex: "not_status",
    formType: "radio",
    hide: true,
    control: (val) => {
      if (val == 1) {
        return {
          days: { display: false },
          weekly: { display: false },
        };
      }
      if (val == 2) {
        return {
          days: { display: true },
          weekly: { display: true },
        };
      }
    },
    search: true,
    commonRules: {
      required: false,
      message: "请输入是否重复设置",
    },
    dict: {
      name: "xjlxtf",
      props: {
        label: "title",
        value: "key",
      },
      translation: true,
    },
  },
  {
    title: "每天次数",
    dataIndex: "days",
    formType: "input",
    hide: true,
  },
  {
    title: "每周次数",
    dataIndex: "weekly",
    formType: "input",
    hide: true,
  },
  {
    title: "备注",
    dataIndex: "remark",
    formType: "textarea",
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true,
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true,
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true,
  },
]);
</script>
<script>
export default { name: "secure:inspectionrouteManage" };
</script>
